package com.baowenli.server;


import com.baowenli.mapper.CheckInMapper;
import com.baowenli.mapper.HandleHouseMapper;
import com.baowenli.mapper.OrderInfoMapper;
import com.baowenli.pojo.CheckIn;
import com.baowenli.pojo.Order;
import com.baowenli.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class CheckInService {
    SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory();

    /**
     *
     * 添加住房登记表
     * @return
     */
    public int insertHousePeopleInfo(int orderid, int roomid, int roomnumber, int pepcount,String persons
            ,String ids) {
        //2.获取sqlSession
        SqlSession sqlSession = factory.openSession();
        //3.获取BrandMapper
        CheckInMapper mapper = sqlSession.getMapper(CheckInMapper.class);
        //4.调用方法
        int temp = mapper.insertPeopleHomeRegister(orderid, roomid, roomnumber, pepcount, persons, ids);
        sqlSession.commit();
        sqlSession.close();
        return temp;
    }



    /**
     *  进行退房登记
     * */
    public int exitHomeRegister(int roomNumber,int orderId){
        //2.获取sqlSession
        SqlSession sqlSession = factory.openSession();
        //3.获取BrandMapper
        CheckInMapper mapper = sqlSession.getMapper(CheckInMapper.class);
        //4.调用方法
        int temp = mapper.exitHomeRegister(roomNumber,orderId);
        sqlSession.commit();
        sqlSession.close();
        return temp;
    }

    /**
     *  进行算出住的天数
     * */
    public CheckIn findHomeCountDay(int roomNumber,int orderId){
        //2.获取sqlSession
        SqlSession sqlSession = factory.openSession();
        //3.获取BrandMapper
        CheckInMapper mapper = sqlSession.getMapper(CheckInMapper.class);
        //4.调用方法
        CheckIn check = mapper.findHomeDateCount(roomNumber,orderId);
        sqlSession.commit();
        sqlSession.close();
        return check;
    }

    /**
     *  进行查找所有住房登记信息
     *
     * */
    public List<CheckIn> findAllEnterRoomInfo(){
        //2.获取sqlSession
        SqlSession sqlSession = factory.openSession();
        //3.获取BrandMapper
        CheckInMapper mapper = sqlSession.getMapper(CheckInMapper.class);
        //4.调用方法
        List<CheckIn> checks = mapper.findAllEnterRoomInfo();
        sqlSession.commit();
        sqlSession.close();
        return checks;
    }
}
